package com.atguigu.gmall.mq.config;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DelayMqConfig {

    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";

    @Bean
    public Exchange exchange(){
        Map<String , Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(exchange_delay, "x-delayed-message",true,false,args);
    }

    @Bean
    public Queue delayqueue(){
        return QueueBuilder.durable(queue_delay_1).build();
    }

    @Bean
    public Binding binding(@Qualifier(value = "delayqueue")Queue queue,@Qualifier(value = "exchange")Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(routing_delay).noargs();
    }
}
